<html><head><title>管理页面</title></head><body>
	<?php
		include_once('mysql_connection.php'); //包含数据库连接文件
		//start 验证cookie，如果没有登录，页面自动转向到登录页面
		if (@ !$_COOKIE['login']=='true') {
		?> 
		<meta http-equiv="Refresh" content="3;URL=guestbook_login.php">
		<div style="text-align:center;padding:50px;border-style:dashed;border-width:1px;">
			您还没有成功，系统将自动跳转到登录页面<br /><br />
			<a href="guestbook_login.php">如果您的浏览器没有自动跳转,请点击这里回到登录页面</a>
		</div>
		<?php
			exit;
			//end
		}
		//start 检测是否是提交表单的请求，如果是连接数据库，删除相应留言
		if ($_SERVER['REQUEST_METHOD']=='POST') {
			$id_message = $_POST['id_message'];
			$query_delete = "delete from `guestbook` where `id`=".$id_message;
			$mysql_connection->query($query_delete);
			echo '<center>删除成功!</center>';
		}
		//end
		//start 查询数据库，列出所有留言，并设置好表单，添加删除按钮
		$query = 'select * from `guestbook` order by `post_time` desc';
		$result = $mysql_connection->query($query);
		$num_rows = $result->num_rows;
	?> 
	<div style="margin-top:70px;text-align:center;border-style:solid;border-width:1px;">
		<a href="index.php">查看首页</a>
		<center><table border="1">
			<?php
				for ($i=0; $i<$num_rows; $i+=1) {
					$row = $result->fetch_assoc();
				?>
				<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
					<tr><td><?php echo $row['ID'];?></td>
					<td><?php echo $row['content'];?></td>
					<td><?php echo $row['post_time'];?></td>
					<td><?php echo $row['nickname'];?></td>
					<td><input type="hidden" name="id_message" id="id_message" value="<?php echo $row['ID'];?>" /><input type="submit" value="删除" /></td></tr>
				</form>
				<?php
				}
			?> 
		</table></center>
	</div>
	<!-- //end -->
</body></html>
